<template>
  <div>
    <h1 @click="txt='blue' " v-color='txt'>自定义指令</h1>
    <input v-focus ref="inp" type="text">
  </div>
</template>

<script>
export default {
  data() {
    return {
      txt: 'red'
    }
  },
  //局部注册自定义指令
 directives:{
  color:{
    inserted(el,binding) {
      el.style.color = binding.value
    },
    update(el,binding) {
      el.style.color = binding.value
    }
  }
 }
}
</script>

<style>

</style>